<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:awc="clr-namespace:Assergs.Windows.Controls"
	xmlns:aw="clr-namespace:Assergs.Windows"
	>

	<SolidColorBrush x:Key="ForegroundBrush" Color="{x:Static aw:TabControlPallet.Foreground}"/>
	<SolidColorBrush x:Key="NormalBorderBrush" Color="{x:Static aw:TabControlPallet.NormalBorder}"/>
	<SolidColorBrush x:Key="BodyBackgroundBrush" Color="{x:Static aw:TabControlPallet.BodyBackground}"/>
	
	<LinearGradientBrush x:Key="ButtonBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
		<GradientStop Color="{x:Static aw:TabControlPallet.ButtonBackground1}" Offset="0"/>
        <GradientStop Color="{x:Static aw:TabControlPallet.ButtonBackground2}" Offset="0.4"/>
        <GradientStop Color="{x:Static aw:TabControlPallet.ButtonBackground3}" Offset="0.4"/>
        <GradientStop Color="{x:Static aw:TabControlPallet.ButtonBackground4}" Offset="1"/>
	</LinearGradientBrush>
	
	<LinearGradientBrush x:Key="ButtonLightBackgroundBrush" StartPoint="0.5,0" EndPoint="0.5,1">
		<GradientStop Color="{x:Static aw:TabControlPallet.ButtonLightBackground1}" Offset="0"/>
		<GradientStop Color="{x:Static aw:TabControlPallet.ButtonLightBackground2}" Offset="0.4"/>
		<GradientStop Color="{x:Static aw:TabControlPallet.ButtonLightBackground3}" Offset="0.4"/>
		<GradientStop Color="{x:Static aw:TabControlPallet.ButtonLightBackground4}" Offset="1"/>
	</LinearGradientBrush>
    
    <Style x:Key="{x:Type TabControl}" TargetType="{x:Type TabControl}">
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="Padding" Value="4,4,4,4"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
        <Setter Property="Background" Value="{StaticResource BodyBackgroundBrush}"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid KeyboardNavigation.TabNavigation="Local" SnapsToDevicePixels="true" ClipToBounds="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="ColumnDefinition0"/>
                            <ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition x:Name="RowDefinition0" Height="Auto"/>
                            <RowDefinition x:Name="RowDefinition1" Height="*"/>
                        </Grid.RowDefinitions>
                        <TabPanel x:Name="HeaderPanel"
                            Panel.ZIndex ="1" 
                            KeyboardNavigation.TabIndex="1"
                            Grid.Column="0"
                            Grid.Row="0"
                            Margin="2,2,2,0"
                            IsItemsHost="true"/>
						<Border x:Name="ContentPanel"
							Background="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            KeyboardNavigation.TabNavigation="Local"
                            KeyboardNavigation.DirectionalNavigation="Contained"
                            KeyboardNavigation.TabIndex="2"
                            Grid.Column="0"
                            Grid.Row="1">
                            <ContentPresenter x:Name="PART_SelectedContentHost"
								SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                Margin="{TemplateBinding Padding}"
                                ContentSource="SelectedContent"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TabStripPlacement" Value="Bottom">
                            <Setter Property="Grid.Row" Value="1" TargetName="HeaderPanel"/>
                            <Setter Property="Grid.Row" Value="0" TargetName="ContentPanel"/>
                            <Setter Property="Height" Value="*" TargetName="RowDefinition0"/>
                            <Setter Property="Height" Value="Auto" TargetName="RowDefinition1"/>
                            <Setter Property="Margin" Value="2,0,2,2" TargetName="HeaderPanel"/>
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Left">
                            <Setter Property="Grid.Row" Value="0" TargetName="HeaderPanel"/>
                            <Setter Property="Grid.Row" Value="0" TargetName="ContentPanel"/>
                            <Setter Property="Grid.Column" Value="0" TargetName="HeaderPanel"/>
                            <Setter Property="Grid.Column" Value="1" TargetName="ContentPanel"/>
                            <Setter Property="Width" Value="Auto" TargetName="ColumnDefinition0"/>
                            <Setter Property="Width" Value="*" TargetName="ColumnDefinition1"/>
                            <Setter Property="Height" Value="*" TargetName="RowDefinition0"/>
                            <Setter Property="Height" Value="0" TargetName="RowDefinition1"/>
                            <Setter Property="Margin" Value="2,2,0,2" TargetName="HeaderPanel"/>
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Right">
                            <Setter Property="Grid.Row" Value="0" TargetName="HeaderPanel"/>
                            <Setter Property="Grid.Row" Value="0" TargetName="ContentPanel"/>
                            <Setter Property="Grid.Column" Value="1" TargetName="HeaderPanel"/>
                            <Setter Property="Grid.Column" Value="0" TargetName="ContentPanel"/>
                            <Setter Property="Width" Value="*" TargetName="ColumnDefinition0"/>
                            <Setter Property="Width" Value="Auto" TargetName="ColumnDefinition1"/>
                            <Setter Property="Height" Value="*" TargetName="RowDefinition0"/>
                            <Setter Property="Height" Value="0" TargetName="RowDefinition1"/>
                            <Setter Property="Margin" Value="0,2,2,2" TargetName="HeaderPanel"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
   
    <Style x:Key="TabItemFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="3,3,3,1"
                               StrokeThickness="1"
                               Stroke="Black"
                               StrokeDashArray="1 2"
                               SnapsToDevicePixels="true"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <SolidColorBrush x:Key="TabItemDisabledBackground" Color="#F4F4F4"/>
    <SolidColorBrush x:Key="TabItemHotBorderBrush" Color="#3C7FB1"/>
    <SolidColorBrush x:Key="TabItemDisabledBorderBrush" Color="#FFC9C7BA"/>
    
    <Style x:Key="{x:Type TabItem}" TargetType="{x:Type TabItem}">
        <Setter Property="FocusVisualStyle" Value="{StaticResource TabItemFocusVisual}"/>
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
        <Setter Property="Padding" Value="6,1,6,1"/>
        <Setter Property="BorderBrush" Value="{StaticResource NormalBorderBrush}"/>
        <Setter Property="Background" Value="{StaticResource ButtonBackgroundBrush}"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabItem}">
                    <Grid SnapsToDevicePixels="true">
                        <Border Name="Bd"
                                Padding="{TemplateBinding Padding}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                Background="{TemplateBinding Background}"
                                BorderThickness="1,1,1,0">
                            <ContentPresenter Name="Content"
                                              ContentSource="Header"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                              HorizontalAlignment="{Binding Path=HorizontalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
                                              VerticalAlignment="{Binding Path=VerticalContentAlignment,RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"
                                              RecognizesAccessKey="True"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="Bd" Property="Background" Value="{StaticResource ButtonLightBackgroundBrush}"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="Panel.ZIndex" Value="1"/>
                            <Setter TargetName="Bd" Property="Background" Value="{StaticResource BodyBackgroundBrush}"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="false"/>
                                <Condition Property="IsMouseOver" Value="true"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource TabItemHotBorderBrush}"/>
                        </MultiTrigger>
                        <Trigger Property="TabStripPlacement" Value="Bottom">
                            <Setter TargetName="Bd" Property="BorderThickness" Value="1,0,1,1"/>
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Left">
                            <Setter TargetName="Bd" Property="BorderThickness" Value="1,1,0,1"/>
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Right">
                            <Setter TargetName="Bd" Property="BorderThickness" Value="0,1,1,1"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="true"/>
                                <Condition Property="TabStripPlacement" Value="Top"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Margin" Value="-2,-2,-2,-1"/>
                            <Setter TargetName="Content" Property="Margin" Value="0,0,0,1"/>                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="true"/>
                                <Condition Property="TabStripPlacement" Value="Bottom"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Margin" Value="-2,-1,-2,-2"/>
                            <Setter TargetName="Content" Property="Margin" Value="0,1,0,0"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="true"/>
                                <Condition Property="TabStripPlacement" Value="Left"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Margin" Value="-2,-2,-1,-2"/>
                            <Setter TargetName="Content" Property="Margin" Value="0,0,1,0"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="true"/>
                                <Condition Property="TabStripPlacement" Value="Right"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Margin" Value="-1,-2,-2,-2"/>
                            <Setter TargetName="Content" Property="Margin" Value="1,0,0,0"/>
                        </MultiTrigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Bd" Property="Background" Value="{StaticResource TabItemDisabledBackground}"/>
                            <Setter TargetName="Bd" Property="BorderBrush" Value="{StaticResource TabItemDisabledBorderBrush}"/>
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>